#ifndef ISHAREDBUFFER_H_
#define ISHAREDBUFFER_H_

#include <utils/RefBase.h>
#include <binder/IInterface.h>
#include <binder/Parcel.h>

#include "SyncBuffer.h"

#define SHARED_BUFFER_SERVICE "com.android.SharedBuffer"

using namespace android;

typedef struct {
    uint32_t int1;
    uint32_t int2;
    uint32_t int3;
    uint32_t int4;
    uint32_t payload_size;
    char payload[0];
} BufferData;

template<typename BUFFER_DATA>
inline BUFFER_DATA buffer_data_cast(void *data) {
    return static_cast<BUFFER_DATA>(data);
}

class ISharedBuffer : public IInterface {
public:
DECLARE_META_INTERFACE(SharedBuffer);

    virtual sp<SyncBuffer> createBuffer(size_t size, const char *name = nullptr) = 0;
    virtual status_t commitBuffer(bool async = false) = 0;
    virtual status_t releaseBuffer() = 0;
};

class BnSharedBuffer : public BnInterface<ISharedBuffer> {
public:
    virtual status_t
    onTransact(uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags = 0);
};

#endif
